(function(jQuery){
    $.unsaferanking = function(){
        this.acNo;
        this.month;
        this.parma;
        this.defaultInit = function(){
            this.acNo = null;
            this.month = null;
            this.parma = {};
			this.eventsBing();
			$("#dataCont").html("");
			$("#msg").hide();
        }
        this.init = function(isRefresh){
			$.iBoxWait();
            $.unsaferanking().defaultInit();
            this.acNo = $("#acNo").html();
            this.month = $("#startDate").html();
			this.month = (this.month).substr(0,7);
            this.parma = {
                "acNo": this.acNo = null ? "" : this.acNo,
                "month": this.month = null ? "" : this.month
            };
            $.ajax({
                //提交数据的类型 POST GET
                type: "POST",
                //提交的网址
                url: queryUrl+"queryCabinClean",
                //提交的数据
                data: "parma=" + JSON.stringify(this.parma),
                //返回数据的格式
                datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                //成功返回之后调用的函数             
                success: function(data){
					iG.ajaxCallback(isRefresh);
                    json = JSON.parse(data);
                    if (json.status == 0) {
                        if (json.arry.length == 0) {
                         $("#msg").show();
						 $.iBoxHide();
                        }
                        else {
                         $.unsaferanking().append(json.arry);
                        }
                    }
                    else {
                        $.iBoxMsg("查询失败");
                    }
                },
                //调用出错执行的函数
                error: function(err){
                    //请求出错处理
                    $.iBoxMsg("网络状态异常");
                }
            });
        };
        
        
        //插入数据
        this.append = function(data){
            var html = $('<div class=" uc-a touming1 umar-b" divInfo onclick="$.toFlyInfo(this.id)">\
				    <ul class="uc-t ub lis  uinn">\
				        <li class=" ub ub-ac umar-a">\
				                <div class="ulev2" style="font-weight:500">\
									<div class="ub ">\
									    <div class="" auto="carrier"></div>\
									    <div class="ub-f1" auto="flightno"></div>\
									</div>\
				                </div>\
				        </li>\
				        <ul class="ub-f1 ub ub-ver umar-l">\
				            <ul class=" ub ">\
				                <li class=" umar-r" >处理部门</li>\
				                <li class="umar-r umar-l" style="font-weight:bolder;" arrangedept auto="arrangedept"></li>\
								<li class="ub-f1 umar-l  tx-r" status auto="status" style="font-weight:bolder;"></li>\
				            </ul>\
				            <ul class="ub " >\
				                <li class="umh2 ub-f1" style="color:#46485f">处理时长</li>\
				                <li style="color:#f15a22" auto="submittimestr" submittimestr></li>\
				            </ul>\
				        </ul>\
				    </ul>\
                     <div class="ub t-bla umar-b ub-ac">\
                         <div class=" ub-f1  uc-l1">\
                             <div class="ub ub-ac ub-pc t-bla">\
                                 <div class="uinn3 uc-t1" style="font-weight:bolder;">机型</div>\
                                 <div class="uinn3 cu " auto="actype"></div>\
                             </div>\
                         </div>\
                         <div class="ub-f1 ">\
                             <div class="ub  ub-ac ub-pc t-bla">\
                                 <div class="uinn3 uc-t1" style="font-weight:bolder;">机号</div>\
                                 <div class="uinn3 cu " auto="acno"></div>\
                             </div>\
                         </div>\
                         <div class="ub-f1  uc-r1">\
                             <div class="ub  ub-ac ub-pc t-bla">\
                                 <div class="uinn3 uc-t1" style="font-weight:bolder;">桥位</div>\
                                 <div class="uinn3 cu " auto="bridge"></div>\
                             </div>\
                         </div>\
                     </div>\
                 <div class="ub">\
                     <div class="uinn2  foup umh1-7 ub-img " style="margin-left:1em">\
                     </div>\
                     <div class=" uinn ub ub-ac ulev0 ub-pc" auto="depairport" style="font-weight:bolder;"></div>\
                     <div class="ub-f2 ">\
                         <div class="ub  ub-ver ub-ac ub-pc ">\
                             <div class="uc-b1  umar-b" style="width:100%">\
								<div class="ub tx-l ">\
								    <div class=""style="color:#46485f">单号：</div>\
								    <div class="ub-f1 " auto="affairno"></div>\
								</div>\
                             </div>\
                             <div class="uc-b1 ubt tx-c uinn" style="width:100%" auto="flightdatestr"></div>\
                         </div>\
                     </div>\
                     <div class="uinn ub ub-ac ulev0 ub-pc" style="margin-left:1em;font-weight:bolder;" auto="arrairport"></div>\
                     <div class=" uinn2  down umh1-7 ub-img" style="margin-right:1em;">\
                     </div>\
                 </div>\
				 <div class="uinn ">\
					<div class="ub ">\
					    <div class="uinn t-wh ulev1  ub ub-ac" style="background-color:#37395c">描<br/>述</div>\
					    <div class="ub-f1 uinn" style="background-color:#d9e0e7;" auto="affairremark"></div>\
					</div>\
                 </div>\
             </div>');
			forData(0);
            var elem;
			function forData(i){
				if (i < data.length) {
					if(data[i].status==3){
								i++;
								forData(i);
					}else{
						$.getJSON("js/clean/citys.png", function(jsons){
						var jso = jsons.array;
						var yes = 0;
						for (var j = 0; j < jso.length; j++) {
							if (jso[j].apt3code == data[i].depairport.toUpperCase()) {
								data[i].depairport1 = data[i].depairport.toUpperCase();
								data[i].depairport =jso[j].aptallzhs;
								yes++;
							}
							if (jso[j].apt3code == data[i].arrairport.toUpperCase()) {
								data[i].arrairport1 = data[i].arrairport.toUpperCase();
								data[i].arrairport = jso[j].aptallzhs;
								yes++;
							}
							if (yes == 2) {
								elem = html.clone(true);
								iG.autoData(data[i], elem);//给属性 对象赋值 
								elem.attr({
									"id":JSON.stringify(data[i]),
								});
								//计算时长
								var submittimestr = elem.find("[submittimestr]").html();
								elem.find("[submittimestr]").html($.unsaferanking().setSubmitTime(submittimestr));
								//处理部门
								var arrangedept = elem.find("[arrangedept]").html();
								if(arrangedept=="1"){
									 elem.find("[arrangedept]").html("地服");
								}else if(arrangedept=="2"){
									 elem.find("[arrangedept]").html("机务");
								}
								//处理状态
								var status = elem.find("[status]").html();
								if(status=="0"){
									 elem.find("[status]").html("待处理").attr("class","t-gra ub-f1 umar-l  tx-r");
								}else if(status=="1"){
									if(data[i].submitdept=='1'){
										 elem.find("[status]").html("待移动地服确认").attr("class","t-lui ub-f1 umar-l  tx-r");
									}else{
										 elem.find("[status]").html("待移动客舱确认").attr("class","t-gra ub-f1 umar-l  tx-r");
									}
								}else if(status=="2"){
									 elem.find("[status]").html("无法解决").attr("class","t-gra ub-f1 umar-l  tx-r");
								}
//								else if(status=="3"){
//									 elem.find("[status]").html("已关闭").attr("class","t-red ub-f1 umar-l  tx-r");
//								}
								else if(status=="4"){
									 elem.find("[status]").html("退回").attr("class","t-org ub-f1 umar-l  tx-r");
								}else if(status=="5"){
									 elem.find("[status]").html("处理中").attr("class","t-blu ub-f1 umar-l  tx-r");
								}
								$("#dataCont").append(elem);
								i++;
								forData(i);
								break;
							}
						}
					})
					}
				
				}else{
						$.iBoxHide();
				}
            }
        };
        //任务超时
        this.setSubmitTime = function(time){
            var num = (Date.parse($.bundDate().CurentTime().replace(/-/g, '/')) - Date.parse(time.replace(/-/g, '/'))) / (1000);
//            var s = num % 60;
            num =parseInt(num / 60);
            var m = num % 60;
            num = parseInt(num / 60);
            var h = num % 24;
            num = parseInt(num / 24);
            var d = num;
			if(d>=0){
				time = d + '天' + h + '小时' + m + '分';
			}else{
				time ='--天--小时--分';
			}
            return time;
        }
        //设置图标
        this.setIcon = function(elem, type){
            var carrier = {
                "MU": "img182",
                "FM": "img11",
                "KN": "img62"
            };
            elem.find("[icon]").addClass(carrier[type] || "img153");
        }
        
	   this.eventsBing = function () {
            //所有事件我们可以在这里绑定
            $("#updateBtn").unbind();
            $("#updateBtn").on('click', function () {
                $.unsaferanking().init();
            });
        };
        return this;
    }
	
	 //到航班信息
        $.toFlyInfo = function(data){
		  setStorage("formJson",data);
		  uexWindow.open("deepCleaningComimt",0,"deepCleaningComimt.html",2,"","","4",280);
		  return true;
        }
})(jQuery);
